package com.dayu.design.结构型.代理模式;

/**
 * 比如在玩“极品飞车”这款游戏，如果游戏者手中的金钱达到了一定的数量就可以到车店买一部性能更高的赛车，那么这个卖车的“车店”
 * 就是一个典型的“汽车厂家”的“代理”，他为汽车厂家“提供卖车的服务”给有需求的人士。从面向对象的方面考虑，“销售汽车的代理”也
 * 是一个对象，那么这个对象也具有一定的状态，在软件项目中这个对象也具有管理财务进销存的基本功能，那么在设计时就要以面向OOP
 * 编程的思想来考虑软件的类结构，这个销售汽车的代理也是一个类了。
 * <p>
 * 【代理模式解释】
 * <p>
 * 类型：结构模式
 * <p>
 * 对一些对象提供代理，以限制那些对象去访问其它对象。
 */
public class agencyDemo {
    public static void main(String[] args) {
        people people_1 = new people();
        people_1.setCash(60000);
        people_1.setUsername("jeck");

        people people_2 = new people();
        people_2.setCash(40000);
        people_2.setUsername("rose");

        people people_3 = new people();
        people_3.setVip("vip");
        people_3.setUsername("tom");

        proxyclass proxyclass = new proxyclass();
        proxyclass.setPeople(people_1);
        proxyclass.buyMycar();

        proxyclass.setPeople(people_2);
        proxyclass.buyMycar();

        proxyclass.setPeople(people_3);
        proxyclass.buyMycar();

    }
}

interface BuyCar {
    public void buyMycar();
}

class people implements BuyCar {
    private int cash;
    private String vip;
    private String username;

    @Override
    public void buyMycar() {
        System.out.println(username + "是vip客户,可以直接购买新车! ");
    }

    public String getVip() {
        return vip;
    }

    public void setVip(String vip) {
        this.vip = vip;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public int getCash() {
        return cash;
    }

    public void setCash(int cash) {
        this.cash = cash;
    }
}

class proxyclass implements BuyCar {
    private people people;

    public people getPeople() {
        return people;
    }

    public void setPeople(people people) {
        this.people = people;
    }

    @Override
    public void buyMycar() {
        if (people.getVip() == "vip") {
            people.buyMycar();
            return;
        }

        if (people.getCash() >= 50000) {
            System.out.println(people.getUsername() + "买了新车,交易结束!");
        } else {
            System.out.println(people.getUsername() + "钱不够,不能买车,继续比赛");
        }
    }
}